package java学习.算法.队列;

import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;

/**
 * **************
 * 项目名称: 蓝桥杯 <br/>
 * 文件名称:  <br/>
 * 文件描述: 这里添加您的类文件描述，说明当前文件要包含的功能。 <br/>
 * 文件创建：刘世锦 <br/>
 * 创建时间: 2022/5/12 <br/>
 *
 * @version v1.0 <br/>
 * @update [序号][日期YYYY-MM-DD][更改人姓名][变更描述]<br/>
 * *************
 */
public class 包含min函数的栈 {
    Stack<Integer> stack = new Stack<Integer>();
    Stack<Integer> min = new Stack<Integer>();
//    Queue<Integer> q=new PriorityQueue();
    public void push1(int node) {
      stack.push(node);
        if (min.size()==0||(node<=min.peek())) {
            min.push(node);
        }
    }

    public void pop1() {
        if (stack.pop()==min1())
        min.pop();
    }

    public int top1() {
        return stack.peek();
    }

    public int min1() {
        return min.peek();
    }
    class ListNode{
        public int val;
        public int min;
        public ListNode next;
        ListNode(int val,int min){
            this.val = val;
            this.min = min;

        }

    }
    ListNode head ;
    public void push(int node) {
        if(head==null){
            head = new ListNode(node,node);
            head.next = null;
        }
        ListNode cur = new ListNode(node,node);
        cur.next = head;
        if (cur.min>head.min){
            cur.min = head.min;
        }
//         cur.min = Math.min(node,head.min);
        head = cur;

//         head = new ListNode(node,Math.min(node,head.min),head);
    }

    public void pop() {
        head = head.next;
    }

    public int top() {
        return head.val;
    }

    public int min() {
        return  head.min;
    }
}
